/**
 * @file e6_t2_q1.c
 * @date 2022-03-09
 * 
 * 
 * @copyright Copyright (c) 2022 cnzyx MIT Licence
 * 
 */

#include<stdio.h>
#include<stdlib.h>

int fun(double a[], int k, int m, double x){
    int mid=(k+m)/2;
    if(k<m){
        if(a[mid]==x){
            return mid;
        }
        if(a[mid]>x){
            fun(a,k,mid,x);
        }else{
            fun(a,mid+1,m,x);
        }
    }else{
        return -1;
    }
}

int main(int argc, char const *argv[])
{
    //UTF-8
    system("chcp 65001");

    double array[100],in_num;
    int result,len=0;
    printf("请输入数据，以空格隔开，以回车结束：\n");
    do{
        scanf("%f",&array[len]);
        len++;
    }while(getchar()!='\n');
    printf("请输入要查找的数据：");
    scanf("%f",&in_num);
    result=fun(array,0,len,in_num);
    printf("结果：");
    if(result==-1){
        printf("未找到");
    }else{
        printf("下标为：%d",result);
    }
    printf("\n");

    //Pause console
    system("pause");
    return 0;
}
